package com.shangcheng.server.controller;

import com.shangcheng.model.domain.PmsProduct;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.PmsProductVo;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.PmsProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
public class PmsProductController {
    @Autowired
    private PmsProductService productService;

    /**
     * 创建商品
     *
     * @param productVo
     * @return
     */
    @PostMapping("/create")
    public Result create(@RequestBody PmsProductVo productVo) {
        productService.create(productVo);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 查询商品
     *
     * @param brandId
     * @param keyword
     * @param pageNum
     * @param pageSize
     * @param productCategoryId
     * @param productSn
     * @param verifyStatus
     * @param publishStatus
     * @return
     */
    @GetMapping("/list")
    public Result list(Integer brandId, String keyword, Integer pageNum, Integer pageSize,
                       Integer productCategoryId, String productSn, Integer verifyStatus, Integer publishStatus) {
        PageResult result = productService.listByPage(brandId, keyword, pageNum, pageSize, productSn, productCategoryId, verifyStatus, publishStatus);

        return new Result(200, result, "操作成功");
    }

    /**
     * 根据商品名称或货号模糊查询
     *
     * @param keyword
     * @return
     */
    @GetMapping("/simpleList")
    public Result simpleList(String keyword) {
        List<PmsProduct> list = productService.simpleList(keyword);
        return new Result(200, list, "操作成功");
    }

    /**
     * 批量修改删除状态
     *
     * @param deleteStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/deleteStatus")
    public Result updateDeleteStatus(@RequestParam Integer deleteStatus, @RequestParam List<Integer> ids) {
        productService.updateDeleteStatus(deleteStatus, ids);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 批量设为新品
     *
     * @param newStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/newStatus")
    public Result updateNewStatus(@RequestParam Integer newStatus, @RequestParam List<Integer> ids) {
        productService.updateNewStatus(newStatus, ids);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 批量上下架商品
     *
     * @param publishStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/publishStatus")
    public Result updatePublishStatus(@RequestParam Integer publishStatus, @RequestParam List<Integer> ids) {
        productService.updatePublishStatus(publishStatus, ids);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 批量推荐商品
     *
     * @param recommendStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public Result updateReocmmandStatus(@RequestParam Integer recommendStatus, @RequestParam List<Integer> ids) {
        productService.updateReocmmandStatus(recommendStatus, ids);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 批量修改审核状态
     *
     * @param verifyStatus
     * @param ids
     * @return
     */
    @PostMapping("/update/verifyStatus")
    public Result updateVerifyStatus(@RequestParam Integer verifyStatus, @RequestParam List<Integer> ids) {
        productService.updateVerifyStatus(verifyStatus, ids);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 根据商品id获取商品编辑信息
     *
     * @param id
     * @return
     */
    @GetMapping("/updateInfo/{id}")
    public Result updateInfoById(@PathVariable Integer id) {
        PmsProductVo vo = productService.updateInfoById(id);
        Result result = new Result();
        result.setCode(200);
        result.setData(vo);
        result.setMessage("操作成功");
        return result;
    }

    /**
     * 更新商品
     * @param id
     * @param productVo
     * @return
     */
    @PostMapping("/update/{id}")
    public Result updateById(@PathVariable Integer id, @RequestBody PmsProductVo productVo) {
        productService.updateById(id, productVo);
        Result result = new Result();
        result.setCode(200);
        result.setMessage("操作成功");
        return result;
    }

}
